<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <title>注册</title>
    <link rel="stylesheet" href="css/reset.css">
    <link rel="stylesheet" href="css/jiazai.css">
    <style>
        .title {
            padding-top: 20px;
            font-size: 18px;
            color: white;
            text-align: center;
            opacity: .8;
        }
        
        .input-wrap {
            padding: 20px;
            box-sizing: border-box;
        }
        
        .input-wrap>input {
            width: 100%;
            box-sizing: border-box;
            padding: 15px 10px;
            margin-top: 15px;
            font-size: 16px;
            color: white;
            background: #353742;
            border-radius: 5px;
        }
        
        .input-wrap>p:first-of-type {
            padding-top: 15px;
            color: #F25B5B;
            opacity: .7;
        }
        
        .input-wrap>p:last-of-type {
            margin-top: 25px;
            padding: 16px;
            text-align: center;
            font-size: 18px;
            color: white;
            background: #2590FE;
            opacity: .7;
            border-radius: 5px;
        }
        
        .invi-code {
            padding: 15px 10px;
            margin-top: 15px;
            font-size: 16px;
            color: white;
            background: #353742;
            border-radius: 5px;
        }
        
        .invi-code>input {
            flex: 1 1 0;
            width: 100%;
            background: transparent;
            color: white;
        }
        
        .invi-code>span {
            flex: 0 0 80px;
            color: #2590FE;
            font-size: 13px;
            text-align: right;
            opacity: .7;
        }
        
        .agree {
            justify-content: flex-start;
            margin-top: 20px;
            font-size: 14px;
            color: white;
        }
        
        .agree>img {
            margin-right: 5px;
        }
        
        .fixed-bottom {
            position: fixed;
            bottom: 40px;
            left: 0;
            right: 0;
            font-size: 14px;
            color: #2590FE;
            text-align: center;
            opacity: .8;
        }
    </style>
</head>

<body style="background:#2a2c35;">
    <div id='app'>


        <!-- 加载中动画 -->
        <div id='jiazai-ani' v-if='jiazai'>
            <div class="arc"></div>
            <h1><span>LOADING</span></h1>
        </div>
        <!-- 加载中动画 -->

        <h1 class='title'>注册账号</h1>

        <div class='input-wrap'>
            <input type="text" placeholder="输入账号（低于20位的数字、字母组合）" v-model='regi.nickname'>
            <input type="text" placeholder="输入手机号" v-model='regi.userphone'>
            <div class='invi-code dis-spa'>
                <input type="text" placeholder="输入验证码" v-model='regi.yzmcode'>
                <span @click='sendCode' v-text='codeFont' :style="{'color':codeFont!='获取验证码'?'#AAAAAA':''}">获取验证码</span>
            </div>
            <input type="password" placeholder="密码由8-20位数字或字母组成" v-model='regi.password'>
            <input type="password" placeholder="确认密码" v-model='regi.password2'>
            <input type="text" placeholder="邀请码" v-model='regi.invicode'>
            <p class='dis-spa'>
                <span v-text='notice'>提示：输入密码有误</span>
            </p>
            <p @click='goRegi'>立即注册</p>
            <div class='agree dis-spa'>
                <img @click='agree=!agree' :src="agree?'./img/yes.png':'./img/no.png'" width="12px" height="12px">
                <span @click='agree=!agree' style="opacity:.7;">同意用户</span>
                <span @click="_openHref({url:'user-xieyi.html',id:'userXieyi'})" style='color:#2590FE;'>《服务协议》</span>
            </div>
        </div>

        <!-- <div class='fixed-bottom' id='fixed-bottom' @click='_close()'>
            已有账号，去登陆
        </div> -->
    </div>
    <script src="js/comm.js"></script>
    <script src="js/vue.min.js"></script>
    <script src="js/TCaptcha.js"></script>
    <script src="js/jquery.min.js"></script>
    <script>
        try {
            var captcha1 = new TencentCaptcha('2077072127', function(result) {
                if (result.ret == 0) {
                    app.slider(result);
                }
            });

        } catch (ex) {
            mui.toast("网络不稳定,即将退出当前页面,请重新进入");
            setTimeout(function() {
                // plus.webview.close();
            }, 500)
        }

        var app = new Vue({
            el: '#app',
            data: {
                h: 0,
                jiazai: false,
                //拖动验证的值
                invi: null,
                //同意用户协议
                agree: false,
                //获取验证码控制字
                codeFont: '获取验证码',
                //注册字段
                regi: {
                    nickname: '',
                    userphone: '',
                    password: '',
                    password2: '',
                    yzmcode: '',
                    agreement: false,
                    invicode: ''
                },
                notice: '',
                //短信验证码
                code: ''
            },
            methods: {
                //滑块验证
                slider: function(res) {
                    var This = this;
                    this.jiazai = true;
                    _post(SLIDER, {
                        Ticket: res.ticket,
                        Randstr: res.randstr,
                    }, function(data) {
                        if (data.status == 1) {
                            This.setTime();
                        } else {
                            This.jiazai = false;
                        }
                    });
                },
                //获取验证码计时
                setTime: function(res) {
                    var This = this;
                    This.jiazai = true;
                    _post(DUANXIN, {
                        mobile: this.regi.userphone,
                        type: 1
                    }, function(data) {
                        This.jiazai = false;
                        if (data.status == 1) {
                            // This.code = data.back;
                            var num = 60;
                            var time = setInterval(function() {
                                if (num-- <= 1) {
                                    clearInterval(time);
                                    This.codeFont = '获取验证码';
                                } else {
                                    This.codeFont = '再次获取' + num + 's';
                                }
                            }, 1000);
                        } else {
                            _toast(data.msg);
                        }
                    });

                },
                //发送验证码
                sendCode: function() {
                    if (this.codeFont != '获取验证码') {
                        return;
                    }
                    if (!_checkMobile(this.regi.userphone)) {
                        _toast('请输入正确的手机号');
                        return;
                    }
                    // this.setTime();
                    captcha1.show();
                },
                //立即注册
                goRegi: function() {
                    this.regi.agreement = this.agree;
                    if (!this.regi.nickname || this.regi.nickname.length > 20) {
                        this.notice = '请输入正确的账号';
                        return;
                    }
                    if (!_checkMobile(this.regi.userphone)) {
                        this.notice = '请输入正确的手机号';
                        return;
                    }
                    if (!this.regi.yzmcode) {
                        this.notice = '请输入有效的验证码';
                        return;
                    }
                    if (this.regi.password != this.regi.password2) {
                        this.notice = '两次登陆密码不一致，请重新输入';
                        return;
                    }
                    if (!this.regi.invicode) {
                        this.notice = '请输入邀请码';
                        return;
                    }
                    if (!this.regi.agreement) {
                        this.notice = '请同意服务协议';
                        return;
                    }
                    var This = this;
                    this.jiazai = true;
                    _post(REGIST, This.regi, function(data) {
                        This.jiazai = false;
                        if (data.status == 1) {
                            _toast('注册成功，请前往登陆');
                            setTimeout(function() {
                                _close();
                            }, 1500);
                        } else {
                            This.notice = data.msg;
                        }
                    });
                }
            }
        });
    </script>
</body>

</html>